﻿using IntelligentAgriculture.Contracts.Dto.Input.ManageInput;
using IntelligentAgriculture.Contracts.Dto.Output.ManageOutput;
using IntelligentAgriculture.Contracts.Interface.IManagements;
using IntelligentAgriculture.Contracts.Interface.Iridgepletype;
using IntelligentAgriculture.WebAPI.Application.Command.ManageCommand;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using IntelligentAgriculture.Contracts.Dto.Output.RidgepOutPut;
using IntelligentAgriculture.Contracts.Dto.Input.RidgepInput;
using IntelligentAgriculture.WebAPI.Application.Command.RidgepCpoamd;
using IntelligentAgriculture.WebAPI.Application.Command.RidgepCommand;
using IntelligentAgriculture.Contracts.Dto.Output.PageOutput;
using IntelligentAgriculture.Contracts.Dto.Input.EarTagInput;
using IntelligentAgriculture.Contracts.Dto.Output.EarTagOutput;
using IntelligentAgriculture.WebAPI.Application.Command.EarTageCommand;
using IntelligentAgriculture.Domain.Entity;

namespace IntelligentAgriculture.WebAPI.Controllers.RidgepoleController
{
    /// <summary>
    /// 栋舍管理控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class RidgepolesController : ControllerBase
    {
        private readonly IridegpoleService _iridegpoleService;
        private readonly TokenService _tokenService;
        private readonly ILogger<RidgepolesController> _logger;
        private readonly IMediator _mediator;
        public RidgepolesController(IridegpoleService iridegpoleService, TokenService tokenService, ILogger<RidgepolesController> logger, IMediator mediator)
        {
            _iridegpoleService = iridegpoleService;
            _tokenService = tokenService;
            _logger = logger;
            _mediator = mediator;
        }


        /// <summary>
        /// 显示，分页，查询功能
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Results<PagesOutput<RidgepShowOutput>>> GetShow([FromQuery]RidgepShowinput? input)
        {
            try
            {
                var list = new RidgepShowCommand(input);
                return await _mediator.Send(list);
            }
            catch (Exception)
            {

                throw;
            }
        }


         /// <summary>
        /// 栋舍添加功能
        /// </summary>
        /// <param name="coomand">添加实体</param>
        /// <returns>返回受影响行数</returns>
        [HttpPost]
        public async Task<Results<int>> AddManager(RidgepAddCommand coomand)
        {
            try
            {
                return await _mediator.Send(coomand);
            }
            catch (Exception)
            {

                throw;
            }
        }



        /// <summary>
        /// 栋舍修改功能
        /// </summary>
        /// <param name="coomand">修改实体</param>
        /// <returns>返回受影响行数</returns>
        [HttpPost]
        public async Task<Results<int>> UpdateManger(RidgepUpdateCommand coomand)
        {
            try
            {
                return await _mediator.Send(coomand);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 栋舍单个逻辑删除处理删除耳标命令的 HTTP DELETE请求。
        /// </summary>
        /// <param name="command">包含要删除的耳标信息的命令对象</param>
        /// <returns>一个表示操作结果的异步任务，返回删除操作的结果</returns>
        [HttpDelete]
        public async Task<Results<int>>Delete(RidgepDeleteCommand command)
        {
            try
            {
                return await _mediator.Send(command);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 栋舍批量逻辑删除 HTTP DELETE 方法发送的批量删除命令
        /// </summary>
        /// <param name="command">包含要执行批量删除操作的命令对象</param>
        /// <returns>一个表示操作结果的异步任务，返回批量删除操作的结果</returns>
        [HttpPut]
        public async Task<Results<int>> DeleteRange(RidgepDeleteRangeCommand command)
        {
            try
            {
                return await _mediator.Send(command);
            }
            catch (Exception)
            {

                throw;
            }
        }



        /// <summary>
        /// 栋舍类型
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public object ShowRidogepolesBreed()
        {
            List<object> list = new List<object>();
            foreach (RidgepTypeDTO item in Enum.GetValues(typeof(RidgepTypeDTO)))
            {
                list.Add(new
                {
                    name = item.ToString(),
                    Value = item
                });
            }
            return Results<object>.DataResult(list);
        }


        /// <summary>
        /// 负责人
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public object ShowPeopleBreed()
        {
            List<object> list = new List<object>();
            foreach (RidgepPeopleDTO item in Enum.GetValues(typeof(RidgepPeopleDTO)))
            {
                list.Add(new
                {
                    name = item.ToString(),
                    Value = item
                });
            }
            return Results<object>.DataResult(list);
        }




        /// <summary>
        /// 反填功能
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Results<RidgepShowOutput>> GetFind(int id)
        {
            try
            {
                var command = new RidgepFindCommand(id);
                var roles = await _mediator.Send(command);
                return roles;
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 根据id获取栋舍
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<Results<IQueryable<Ridgepole>>> GetRidgepoles([FromQuery]GetRidgepolesCommand command)
        {
            try
            {
                return Results<IQueryable<Ridgepole>>.DataResult(await _mediator.Send(command));
            }
            catch (Exception)
            {

                throw;
            }
        }



	}
}
